<template>
  <div class="content">
    <div class="common-header-wrap">
      <mt-header class="common-header" :title="title">
        <mt-button icon="back" slot="left" @click="goBack"></mt-button>
      </mt-header>
    </div>
    <store-product-list
      :items="listData"
      v-if="this.listData && this.listData.length"
      v-infinite-scroll="loadMore"
      infinite-scroll-disabled="loading"
      infinite-scroll-distance="10"
    ></store-product-list>
    <empty-record v-if="!this.listData.length"></empty-record>
  </div>
</template>
<script>
import { getCateGoodsList } from "../../../api/homestoredetail";
import StoreProductList from "./StoreProductList";
import EmptyRecord from "../../../components/EmptyRecord";
export default {
  name: "StoreRecommendation",
  data() {
    return {
      title: this.$route.query.vuale == 2 ? "新品列表" : "推荐列表",
      store_id: this.$route.query.id,
      storegc_id: this.$route.query.storegId,
      type: this.$route.query.vuale,
      listData: "",
      params: { page: 1, per_page: 10 },
      loading: false, // 是否加载更多
      isMore: true, // 是否有更多
    };
  },
  created() {
    console.log(this.$route.query.id);
    console.log(this.$route.query.vuale);
    console.log(this.$route.query.storegId);
    this.getCateGoodsList();
  },
  methods: {
    loadMore() {
      this.loading = true;
      this.params.page = ++this.params.page;
      if (this.isMore) {
        this.loading = false;
        this.getCateGoodsList();
        // this.getArticleList(true)
      }
    },
    goBack() {
      this.$router.go(-1);
    },

    getCateGoodsList() {
      getCateGoodsList(this.store_id, this.storegc_id, this.type,this.params).then(
        (res) => {
          console.log(res);
          if (res.code == 10000) {
            if (res.result.hasmore) {
              this.isMore = true;
            } else {
              this.isMore = false;
            }
            if (this.listData.length) {
              this.listData = this.listData.concat(
                res.result.goods_list
              );
            } else {
              this.listData = res.result.goods_list;
            }
            console.log(this.listData)
            // this.listData = res.result.goods_list;
          }
        }
      );
    },
  },
  components: {
    StoreProductList,
    EmptyRecord,
  },
};
</script>